<?php
	/**
	*Author 雷日锦 362606856@qq.com 
	*控制器自动生成
	*/
	if(!defined("ROOT_PATH")) exit("die Access ");
	class kcorderControl extends skymvc{
		public $tbs=array(
			1=>"ymdian",
			2=>"koudai"
		);
		public function __construct(){
			parent::__construct();
			
		}
		
		public function onDefault(){
			$typeid=get('typeid','i');
			$where=" status in(0,1,2,3) ";
			$url=APPADMIN."?m=kcorder&a=default";
			if($typeid){
				$where.=" AND typeid=".$typeid;
				$url.="&typeid=".$typeid;
			}
			$orderno=get('orderno','h');
			if($orderno){
				$where.=" AND orderno='".$orderno."' ";
				$url.="&orderno=$orderno";
			}
			$status=get('s_status','i');
			if($status>=0){
				$where.=" AND status=$status";
				$url.="&s_status=$status";
			}else{
				$url.="&s_status=-1";
			}
			
			$start_time=get('start_time','h');
			$end_time=get('end_time','h');
			if($start_time){
				$where.=" AND dateline>".strtotime($start_time)." ";
				$url.="&start_time=".$start_time;
			}
			
			if($end_time){
				$where.=" AND dateline<".strtotime($end_time)." ";
				$url.="&end_time=".$end_time;
			}
			
			$siteid=get('siteid','i');
			if($siteid){
				$where.=" AND siteid=".$siteid;
				$url.="&siteid=".$siteid;
			}
			
			$kcid=get('kcid','i');
			if($kcid){
				$where.=" AND kcid=".$kcid;
				$url.="&kcid=".$kcid;
			}
			$shopname=get('shopname','h');
			if($shopname){
				$typeid=max(1,$typeid);
				$shopid=M($this->tbs[$typeid])->selectOne(array(
					"where"=>"title='".$shopname."'",
					"fields"=>"id"
				));
				if($shopid){
					$where.=" AND shopid=".$shopid;
				}else{
					$where.=" AND 1=2 ";
				}
				
			}
			$limit=40;
			$start=get("per_page","i");
			$option=array(
				"start"=>intval(get_post('per_page')),
				"limit"=>$limit,
				"order"=>" order_id DESC",
				"where"=>$where
			);
			$rscount=true;
			$data=M("kcorder")->select($option,$rscount);
			if($data){
				foreach($data as $k=>$v){
					$shopids[]=$v['shopid'];
					$siteids[]=$v['siteid'];
					$kcids[]=$v['kcid'];
				}
				$shops=M($this->tbs[$v['typeid']])->getShopByIds($shopids);
			 	$sites=M("sites")->getByIds($siteids);
				$kclist=M("kucun")->getListByIds($kcids);
				foreach($data as $k=>$v){
					$v['shop_name']=$shops[$v['shopid']]['title'];
					$v['address']=$shops[$v['shopid']]['address'];
					$v['sitename']=$sites[$v['siteid']]['sitename'];
					$v['kc_title']=$kclist[$v['kcid']]['title'];
					$data[$k]=$v;
				}
				
			}
			$pagelist=$this->pagelist($rscount,$limit,$url);
			$order_status_list=$this->config_item('order_status_list');
			$this->smarty->assign(
				array(
					"data"=>$data,
					"typeid"=>$typeid,
					"pagelist"=>$pagelist,
					"rscount"=>$rscount,
					"order_status_list"=>$order_status_list,
					"url"=>$url
				)
			);
			$this->smarty->display("kcorder/index.html");
		}
		
		public function onShow(){
			$typeid=max(1,get_post('typeid','i'));
			$order_id=get_post("order_id","i");
			$data=M("kcorder")->selectRow(array("where"=>"order_id={$order_id}"));
			if($data){
				$site=M("sites")->selectRow("siteid=".$data['siteid']);
				
				$shop=M($this->tbs[$data['typeid']])->selectRow(" id=".$data['shopid']);
				
				$order_product=M("kcorder_product")->select(array("where"=>"order_id=".$data['order_id']));
				if($order_product){
					foreach($order_product as $k=>$v){
						$ids[]=$v['productid'];
					}
					$products=M("product")->getListByIds($ids);
					 
					foreach($order_product as $k=>$v){
						$v['title']=$products[$v['productid']]['title'];
						$v['imgurl']=$products[$v['productid']]['imgurl'];
						$v['p_price']=$products[$v['productid']]['price'];
						$order_product[$k]=$v;
					}
				}
			}
			$order_status_list=$this->config_item('order_status_list');
			$this->smarty->assign(array(
				"data"=>$data,
				"shop"=>$shop,
				"order_status_list"=>$order_status_list,
				"order_product"=>$order_product,
				"site"=>$site,
				"typeid"=>$typeid,
			));
			$this->smarty->display("kcorder/show.html");
		}
		 
		
	}

?>